package com.hdl.service.impl;

import com.hdl.anno.Autowired;
import com.hdl.anno.Service;
import com.hdl.anno.Transactional;
import com.hdl.dao.AccountDao;
import com.hdl.pojo.Account;
import com.hdl.service.TransferService;

/**
 * @author hedonglin
 * @date 2020/5/3 11:52
 * @description 转账接口实现类
 */
@Service(value = "transferService")
public class TransferServiceImpl implements TransferService {
    @Autowired
    private AccountDao accountDao;

    @Transactional
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
            int i = 1/0;
            accountDao.updateAccountByCardNo(from);
    }
}
